<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;
use think\model\concern\SoftDelete;

/**
 * @property bool $pay_status 支付状态:1=待支付,2=待取货,3=待评价,4=已完成,5=已取消
 * @property float $coupon_amount 优惠金额
 * @property float $pay_amount 支付金额
 * @property float $total_amount 总金额
 * @property int $canceltime 取消时间
 * @property int $coupon_id 优惠券
 * @property int $deletetime
 * @property int $id
 * @property int $paytime 支付时间
 * @property int $take_delivery_id 提货人
 * @property int $user_id 用户
 * @property string $createtime
 * @property string $mark 订单备注
 * @property string $order_sn 订单编号
 * @property-read \app\model\GoodsOrdersDetail[] $detail
 * @property-read \app\model\TakeDelivery $take_delivery
 * @property-read \app\model\User $user
 * @property-read mixed $canceltime_text
 * @property-read mixed $pay_status_text
 * @property-read mixed $paytime_text
 * @method static \think\db\Query onlyTrashed()
 * @method static \think\db\Query withTrashed()
 * @mixin \think\Model
 */
class GoodsOrders extends Model
{
	use SoftDelete;
	//
	protected $createTime = 'createtime';
	protected $updateTime = 'updatetime';
	protected $deleteTime = 'deletetime';
	protected $append = [
		'paytime_text',
		'pay_status_text',
		'canceltime_text',
	];

	
	public function getPayStatusTextAttr($value, $data)
	{
		$value = $value ? $value : ($data['pay_status'] ?? '');
		$list = ['1' => '待支付', '2' => '待取货', '3' => '待评价', '4' => '已完成', '5' => '已取消'];
		return $list[$value] ?? '';
	}

	
	function getPaytimeTextAttr($value,$data)
	{
		$value = $value ?? ($data['paytime'] ?? "");
		return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
	}
	
	function getCanceltimeTextAttr($value,$data)
	{
		$value = $value ?? ($data['canceltime'] ?? "");
		return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
	}
	
	function user()
	{
		return $this->belongsTo(User::class,'user_id');
	}
	
	function detail()
	{
		return $this->hasMany(GoodsOrdersDetail::class,'order_id');
	}
	
	function takeDelivery()
	{
		return $this->belongsTo(TakeDelivery::class,'take_delivery_id');
	}
	
	
	
}
